package org.jivesoftware.smack;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.Constructor;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyStore;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.Security;
import java.util.Collection;
import java.util.Iterator;
import javax.net.SocketFactory;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import org.apache.harmony.javax.security.auth.callback.Callback;
import org.apache.harmony.javax.security.auth.callback.CallbackHandler;
import org.apache.harmony.javax.security.auth.callback.PasswordCallback;
import org.jivesoftware.smack.debugger.SmackDebugger;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smack.packet.XMPPError.Condition;
import org.jivesoftware.smack.util.StringUtils;

public class XMPPConnection extends Connection
{
  private boolean anonymous;
  private boolean authenticated;
  private Collection<String> compressionMethods;
  private boolean connected;
  String connectionID = null;
  PacketReader packetReader;
  PacketWriter packetWriter;
  Roster roster;
  protected Socket socket;
  private String user = null;
  private boolean usingCompression;
  private boolean usingTLS;
  private boolean wasAuthenticated;

  public XMPPConnection(String paramString)
  {
    super(new ConnectionConfiguration(paramString));
    this.connected = false;
    this.authenticated = false;
    this.wasAuthenticated = false;
    this.anonymous = false;
    this.usingTLS = false;
    this.roster = null;
    this.config.setCompressionEnabled(false);
    this.config.setSASLAuthenticationEnabled(true);
    this.config.setDebuggerEnabled(DEBUG_ENABLED);
  }

  public XMPPConnection(String paramString, CallbackHandler paramCallbackHandler)
  {
    super(new ConnectionConfiguration(paramString));
    this.connected = false;
    this.authenticated = false;
    this.wasAuthenticated = false;
    this.anonymous = false;
    this.usingTLS = false;
    this.roster = null;
    this.config.setCompressionEnabled(false);
    this.config.setSASLAuthenticationEnabled(true);
    this.config.setDebuggerEnabled(DEBUG_ENABLED);
    this.config.setCallbackHandler(paramCallbackHandler);
  }

  public XMPPConnection(ConnectionConfiguration paramConnectionConfiguration)
  {
    super(paramConnectionConfiguration);
    this.connected = false;
    this.authenticated = false;
    this.wasAuthenticated = false;
    this.anonymous = false;
    this.usingTLS = false;
    this.roster = null;
  }

  public XMPPConnection(ConnectionConfiguration paramConnectionConfiguration, CallbackHandler paramCallbackHandler)
  {
    super(paramConnectionConfiguration);
    this.connected = false;
    this.authenticated = false;
    this.wasAuthenticated = false;
    this.anonymous = false;
    this.usingTLS = false;
    this.roster = null;
    paramConnectionConfiguration.setCallbackHandler(paramCallbackHandler);
  }

  private void connectUsingConfiguration(ConnectionConfiguration paramConnectionConfiguration)
    throws XMPPException
  {
    String str1 = paramConnectionConfiguration.getHost();
    int i = paramConnectionConfiguration.getPort();
    try
    {
      try
      {
        if (paramConnectionConfiguration.getSocketFactory() == null)
        {
          this.socket = new Socket(str1, i);
          initConnection();
          return;
        }
        this.socket = paramConnectionConfiguration.getSocketFactory().createSocket(str1, i);
      }
      catch (UnknownHostException localUnknownHostException)
      {
        String str3 = "Could not connect to " + str1 + ":" + i + ".";
        throw new XMPPException(str3, new XMPPError(XMPPError.Condition.remote_server_timeout, str3), localUnknownHostException);
      }
    }
    catch (IOException localIOException)
    {
      String str2 = "XMPPError connecting to " + str1 + ":" + i + ".";
      throw new XMPPException(str2, new XMPPError(XMPPError.Condition.remote_server_error, str2), localIOException);
    }
  }

  private boolean hasAvailableCompressionMethod(String paramString)
  {
    int i;
    if ((this.compressionMethods != null) && (this.compressionMethods.contains(paramString)))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  private void initConnection()
    throws XMPPException
  {
    int i;
    Iterator localIterator;
    if ((this.packetReader != null) && (this.packetWriter != null))
    {
      i = 0;
      if (i == 0)
        this.usingCompression = false;
      initReaderAndWriter();
      if (i != 0);
    }
    try
    {
      this.packetWriter = new PacketWriter(this);
      this.packetReader = new PacketReader(this);
      if (this.config.isDebuggerEnabled())
      {
        addPacketListener(this.debugger.getReaderListener(), null);
        if (this.debugger.getWriterListener() != null)
          addPacketSendingListener(this.debugger.getWriterListener(), null);
      }
      this.packetWriter.startup();
      this.packetReader.startup();
      this.connected = true;
      this.packetWriter.startKeepAliveProcess();
      if (i != 0)
      {
        localIterator = getConnectionCreationListeners().iterator();
        if (!(localIterator.hasNext()))
        {
          break label353:
          this.packetWriter.init();
          label268: label353: this.packetReader.init();
        }
      }
    }
    catch (XMPPException localXMPPException)
    {
      if (this.packetWriter != null);
      try
      {
        this.packetWriter.shutdown();
        this.packetWriter = null;
        if (this.packetReader != null);
      }
      catch (Throwable localThrowable4)
      {
        try
        {
          this.packetReader.shutdown();
          this.packetReader = null;
          if (this.reader != null);
        }
        catch (Throwable localThrowable4)
        {
          try
          {
            this.reader.close();
            this.reader = null;
            if (this.writer != null);
          }
          catch (Throwable localThrowable4)
          {
            try
            {
              this.writer.close();
              this.writer = null;
              if (this.socket != null);
            }
            catch (Throwable localThrowable4)
            {
              try
              {
                while (true)
                {
                  this.socket.close();
                  this.socket = null;
                  setWasAuthenticated(this.authenticated);
                  this.authenticated = false;
                  this.connected = false;
                  throw localXMPPException;
                  ((ConnectionCreationListener)localIterator.next()).connectionCreated(this);
                }
                if (!(this.wasAuthenticated))
                  this.packetReader.notifyReconnection();
              }
              catch (Exception localException)
              {
                while (true)
                {
                  while (true)
                  {
                    while (true)
                    {
                      while (true)
                      {
                        break label268:
                        localThrowable1 = localThrowable1;
                      }
                      localThrowable2 = localThrowable2;
                    }
                    localThrowable3 = localThrowable3;
                  }
                  localThrowable4 = localThrowable4;
                }
              }
              return;
              i = 1;
            }
          }
        }
      }
    }
  }

  // ERROR //
  private void initReaderAndWriter()
    throws XMPPException
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 167	org/jivesoftware/smack/XMPPConnection:usingCompression	Z
    //   4: ifne +64 -> 68
    //   7: aload_0
    //   8: new 265	java/io/BufferedReader
    //   11: dup
    //   12: new 267	java/io/InputStreamReader
    //   15: dup
    //   16: aload_0
    //   17: getfield 99	org/jivesoftware/smack/XMPPConnection:socket	Ljava/net/Socket;
    //   20: invokevirtual 271	java/net/Socket:getInputStream	()Ljava/io/InputStream;
    //   23: ldc_w 273
    //   26: invokespecial 276	java/io/InputStreamReader:<init>	(Ljava/io/InputStream;Ljava/lang/String;)V
    //   29: invokespecial 279	java/io/BufferedReader:<init>	(Ljava/io/Reader;)V
    //   32: putfield 234	org/jivesoftware/smack/XMPPConnection:reader	Ljava/io/Reader;
    //   35: aload_0
    //   36: new 281	java/io/BufferedWriter
    //   39: dup
    //   40: new 283	java/io/OutputStreamWriter
    //   43: dup
    //   44: aload_0
    //   45: getfield 99	org/jivesoftware/smack/XMPPConnection:socket	Ljava/net/Socket;
    //   48: invokevirtual 287	java/net/Socket:getOutputStream	()Ljava/io/OutputStream;
    //   51: ldc_w 273
    //   54: invokespecial 290	java/io/OutputStreamWriter:<init>	(Ljava/io/OutputStream;Ljava/lang/String;)V
    //   57: invokespecial 293	java/io/BufferedWriter:<init>	(Ljava/io/Writer;)V
    //   60: putfield 243	org/jivesoftware/smack/XMPPConnection:writer	Ljava/io/Writer;
    //   63: aload_0
    //   64: invokevirtual 296	org/jivesoftware/smack/XMPPConnection:initDebugger	()V
    //   67: return
    //   68: ldc_w 298
    //   71: invokestatic 304	java/lang/Class:forName	(Ljava/lang/String;)Ljava/lang/Class;
    //   74: astore_3
    //   75: iconst_2
    //   76: anewarray 300	java/lang/Class
    //   79: astore 4
    //   81: aload 4
    //   83: iconst_0
    //   84: ldc_w 306
    //   87: aastore
    //   88: aload 4
    //   90: iconst_1
    //   91: getstatic 312	java/lang/Integer:TYPE	Ljava/lang/Class;
    //   94: aastore
    //   95: aload_3
    //   96: aload 4
    //   98: invokevirtual 316	java/lang/Class:getConstructor	([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;
    //   101: astore 5
    //   103: iconst_2
    //   104: anewarray 318	java/lang/Object
    //   107: astore 6
    //   109: aload 6
    //   111: iconst_0
    //   112: aload_0
    //   113: getfield 99	org/jivesoftware/smack/XMPPConnection:socket	Ljava/net/Socket;
    //   116: invokevirtual 287	java/net/Socket:getOutputStream	()Ljava/io/OutputStream;
    //   119: aastore
    //   120: aload 6
    //   122: iconst_1
    //   123: bipush 9
    //   125: invokestatic 322	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
    //   128: aastore
    //   129: aload 5
    //   131: aload 6
    //   133: invokevirtual 328	java/lang/reflect/Constructor:newInstance	([Ljava/lang/Object;)Ljava/lang/Object;
    //   136: astore 7
    //   138: iconst_1
    //   139: anewarray 300	java/lang/Class
    //   142: astore 8
    //   144: aload 8
    //   146: iconst_0
    //   147: getstatic 312	java/lang/Integer:TYPE	Ljava/lang/Class;
    //   150: aastore
    //   151: aload_3
    //   152: ldc_w 330
    //   155: aload 8
    //   157: invokevirtual 334	java/lang/Class:getMethod	(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
    //   160: astore 9
    //   162: iconst_1
    //   163: anewarray 318	java/lang/Object
    //   166: astore 10
    //   168: aload 10
    //   170: iconst_0
    //   171: iconst_2
    //   172: invokestatic 322	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
    //   175: aastore
    //   176: aload 9
    //   178: aload 7
    //   180: aload 10
    //   182: invokevirtual 340	java/lang/reflect/Method:invoke	(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    //   185: pop
    //   186: aload_0
    //   187: new 281	java/io/BufferedWriter
    //   190: dup
    //   191: new 283	java/io/OutputStreamWriter
    //   194: dup
    //   195: aload 7
    //   197: checkcast 306	java/io/OutputStream
    //   200: ldc_w 273
    //   203: invokespecial 290	java/io/OutputStreamWriter:<init>	(Ljava/io/OutputStream;Ljava/lang/String;)V
    //   206: invokespecial 293	java/io/BufferedWriter:<init>	(Ljava/io/Writer;)V
    //   209: putfield 243	org/jivesoftware/smack/XMPPConnection:writer	Ljava/io/Writer;
    //   212: ldc_w 342
    //   215: invokestatic 304	java/lang/Class:forName	(Ljava/lang/String;)Ljava/lang/Class;
    //   218: astore 12
    //   220: iconst_1
    //   221: anewarray 300	java/lang/Class
    //   224: astore 13
    //   226: aload 13
    //   228: iconst_0
    //   229: ldc_w 344
    //   232: aastore
    //   233: aload 12
    //   235: aload 13
    //   237: invokevirtual 316	java/lang/Class:getConstructor	([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;
    //   240: astore 14
    //   242: iconst_1
    //   243: anewarray 318	java/lang/Object
    //   246: astore 15
    //   248: aload 15
    //   250: iconst_0
    //   251: aload_0
    //   252: getfield 99	org/jivesoftware/smack/XMPPConnection:socket	Ljava/net/Socket;
    //   255: invokevirtual 271	java/net/Socket:getInputStream	()Ljava/io/InputStream;
    //   258: aastore
    //   259: aload 14
    //   261: aload 15
    //   263: invokevirtual 328	java/lang/reflect/Constructor:newInstance	([Ljava/lang/Object;)Ljava/lang/Object;
    //   266: astore 16
    //   268: iconst_1
    //   269: anewarray 300	java/lang/Class
    //   272: astore 17
    //   274: aload 17
    //   276: iconst_0
    //   277: getstatic 312	java/lang/Integer:TYPE	Ljava/lang/Class;
    //   280: aastore
    //   281: aload 12
    //   283: ldc_w 330
    //   286: aload 17
    //   288: invokevirtual 334	java/lang/Class:getMethod	(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
    //   291: astore 18
    //   293: iconst_1
    //   294: anewarray 318	java/lang/Object
    //   297: astore 19
    //   299: aload 19
    //   301: iconst_0
    //   302: iconst_2
    //   303: invokestatic 322	java/lang/Integer:valueOf	(I)Ljava/lang/Integer;
    //   306: aastore
    //   307: aload 18
    //   309: aload 16
    //   311: aload 19
    //   313: invokevirtual 340	java/lang/reflect/Method:invoke	(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    //   316: pop
    //   317: aload_0
    //   318: new 265	java/io/BufferedReader
    //   321: dup
    //   322: new 267	java/io/InputStreamReader
    //   325: dup
    //   326: aload 16
    //   328: checkcast 344	java/io/InputStream
    //   331: ldc_w 273
    //   334: invokespecial 276	java/io/InputStreamReader:<init>	(Ljava/io/InputStream;Ljava/lang/String;)V
    //   337: invokespecial 279	java/io/BufferedReader:<init>	(Ljava/io/Reader;)V
    //   340: putfield 234	org/jivesoftware/smack/XMPPConnection:reader	Ljava/io/Reader;
    //   343: goto -280 -> 63
    //   346: astore_2
    //   347: aload_2
    //   348: invokevirtual 347	java/lang/Exception:printStackTrace	()V
    //   351: aload_0
    //   352: new 265	java/io/BufferedReader
    //   355: dup
    //   356: new 267	java/io/InputStreamReader
    //   359: dup
    //   360: aload_0
    //   361: getfield 99	org/jivesoftware/smack/XMPPConnection:socket	Ljava/net/Socket;
    //   364: invokevirtual 271	java/net/Socket:getInputStream	()Ljava/io/InputStream;
    //   367: ldc_w 273
    //   370: invokespecial 276	java/io/InputStreamReader:<init>	(Ljava/io/InputStream;Ljava/lang/String;)V
    //   373: invokespecial 279	java/io/BufferedReader:<init>	(Ljava/io/Reader;)V
    //   376: putfield 234	org/jivesoftware/smack/XMPPConnection:reader	Ljava/io/Reader;
    //   379: aload_0
    //   380: new 281	java/io/BufferedWriter
    //   383: dup
    //   384: new 283	java/io/OutputStreamWriter
    //   387: dup
    //   388: aload_0
    //   389: getfield 99	org/jivesoftware/smack/XMPPConnection:socket	Ljava/net/Socket;
    //   392: invokevirtual 287	java/net/Socket:getOutputStream	()Ljava/io/OutputStream;
    //   395: ldc_w 273
    //   398: invokespecial 290	java/io/OutputStreamWriter:<init>	(Ljava/io/OutputStream;Ljava/lang/String;)V
    //   401: invokespecial 293	java/io/BufferedWriter:<init>	(Ljava/io/Writer;)V
    //   404: putfield 243	org/jivesoftware/smack/XMPPConnection:writer	Ljava/io/Writer;
    //   407: goto -344 -> 63
    //   410: astore_1
    //   411: new 76	XMPPException
    //   414: dup
    //   415: ldc_w 349
    //   418: new 130	org/jivesoftware/smack/packet/XMPPError
    //   421: dup
    //   422: getstatic 147	org/jivesoftware/smack/packet/XMPPError$Condition:remote_server_error	Lorg/jivesoftware/smack/packet/XMPPError$Condition;
    //   425: ldc_w 349
    //   428: invokespecial 139	org/jivesoftware/smack/packet/XMPPError:<init>	(Lorg/jivesoftware/smack/packet/XMPPError$Condition;Ljava/lang/String;)V
    //   431: aload_1
    //   432: invokespecial 142	XMPPException:<init>	(Ljava/lang/String;Lorg/jivesoftware/smack/packet/XMPPError;Ljava/lang/Throwable;)V
    //   435: athrow
    //
    // Exception table:
    //   from	to	target	type
    //   68	343	346	java/lang/Exception
    //   0	63	410	java/io/IOException
    //   68	343	410	java/io/IOException
    //   347	407	410	java/io/IOException
  }

  private void requestStreamCompression()
  {
    try
    {
      this.writer.write("<compress xmlns='http://jabber.org/protocol/compress'>");
      this.writer.write("<method>zlib</method></compress>");
      this.writer.flush();
      return;
    }
    catch (IOException localIOException)
    {
      this.packetReader.notifyConnectionError(localIOException);
    }
  }

  private void setWasAuthenticated(boolean paramBoolean)
  {
    if (!(this.wasAuthenticated))
      this.wasAuthenticated = paramBoolean;
  }

  // ERROR //
  private boolean useCompression()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 42	org/jivesoftware/smack/XMPPConnection:authenticated	Z
    //   4: ifeq +14 -> 18
    //   7: new 371	java/lang/IllegalStateException
    //   10: dup
    //   11: ldc_w 373
    //   14: invokespecial 374	java/lang/IllegalStateException:<init>	(Ljava/lang/String;)V
    //   17: athrow
    //   18: ldc_w 298
    //   21: invokestatic 304	java/lang/Class:forName	(Ljava/lang/String;)Ljava/lang/Class;
    //   24: pop
    //   25: aload_0
    //   26: ldc_w 376
    //   29: invokespecial 378	org/jivesoftware/smack/XMPPConnection:hasAvailableCompressionMethod	(Ljava/lang/String;)Z
    //   32: ifeq +47 -> 79
    //   35: aload_0
    //   36: invokespecial 380	org/jivesoftware/smack/XMPPConnection:requestStreamCompression	()V
    //   39: aload_0
    //   40: monitorenter
    //   41: aload_0
    //   42: iconst_5
    //   43: invokestatic 385	org/jivesoftware/smack/SmackConfiguration:getPacketReplyTimeout	()I
    //   46: imul
    //   47: i2l
    //   48: invokevirtual 389	java/lang/Object:wait	(J)V
    //   51: aload_0
    //   52: monitorexit
    //   53: aload_0
    //   54: getfield 167	org/jivesoftware/smack/XMPPConnection:usingCompression	Z
    //   57: istore_3
    //   58: iload_3
    //   59: ireturn
    //   60: astore_1
    //   61: new 371	java/lang/IllegalStateException
    //   64: dup
    //   65: ldc_w 391
    //   68: invokespecial 374	java/lang/IllegalStateException:<init>	(Ljava/lang/String;)V
    //   71: athrow
    //   72: astore 5
    //   74: aload_0
    //   75: monitorexit
    //   76: aload 5
    //   78: athrow
    //   79: iconst_0
    //   80: istore_3
    //   81: goto -23 -> 58
    //   84: astore 4
    //   86: goto -35 -> 51
    //
    // Exception table:
    //   from	to	target	type
    //   18	25	60	java/lang/ClassNotFoundException
    //   41	51	72	finally
    //   51	53	72	finally
    //   74	76	72	finally
    //   41	51	84	java/lang/InterruptedException
  }

  public void addPacketWriterInterceptor(PacketInterceptor paramPacketInterceptor, PacketFilter paramPacketFilter)
  {
    addPacketInterceptor(paramPacketInterceptor, paramPacketFilter);
  }

  public void addPacketWriterListener(PacketListener paramPacketListener, PacketFilter paramPacketFilter)
  {
    addPacketSendingListener(paramPacketListener, paramPacketFilter);
  }

  public void connect()
    throws XMPPException
  {
    connectUsingConfiguration(this.config);
    if ((this.connected) && (this.wasAuthenticated))
      try
      {
        if (isAnonymous())
        {
          loginAnonymously();
          this.packetReader.notifyReconnection();
        }
        else
        {
          login(this.config.getUsername(), this.config.getPassword(), this.config.getResource());
        }
      }
      catch (XMPPException localXMPPException)
      {
        localXMPPException.printStackTrace();
      }
  }

  public void disconnect(Presence paramPresence)
  {
    if ((this.packetReader == null) || (this.packetWriter == null));
    while (true)
    {
      return;
      shutdown(paramPresence);
      if (this.roster != null)
      {
        this.roster.cleanup();
        this.roster = null;
      }
      this.wasAuthenticated = false;
      this.packetWriter.cleanup();
      this.packetWriter = null;
      this.packetReader.cleanup();
      this.packetReader = null;
    }
  }

  public String getConnectionID()
  {
    String str;
    if (!(isConnected()))
      str = null;
    while (true)
    {
      return str;
      str = this.connectionID;
    }
  }

  // ERROR //
  public Roster getRoster()
  {
    // Byte code:
    //   0: aload_0
    //   1: getfield 50	org/jivesoftware/smack/XMPPConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   4: ifnonnull +7 -> 11
    //   7: aconst_null
    //   8: astore_1
    //   9: aload_1
    //   10: areturn
    //   11: aload_0
    //   12: getfield 50	org/jivesoftware/smack/XMPPConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   15: getfield 440	org/jivesoftware/smack/Roster:rosterInitialized	Z
    //   18: ifne +33 -> 51
    //   21: aload_0
    //   22: getfield 50	org/jivesoftware/smack/XMPPConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   25: astore_3
    //   26: aload_3
    //   27: monitorenter
    //   28: invokestatic 385	org/jivesoftware/smack/SmackConfiguration:getPacketReplyTimeout	()I
    //   31: i2l
    //   32: lstore 5
    //   34: invokestatic 446	java/lang/System:currentTimeMillis	()J
    //   37: lstore 7
    //   39: aload_0
    //   40: getfield 50	org/jivesoftware/smack/XMPPConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   43: getfield 440	org/jivesoftware/smack/Roster:rosterInitialized	Z
    //   46: ifeq +13 -> 59
    //   49: aload_3
    //   50: monitorexit
    //   51: aload_0
    //   52: getfield 50	org/jivesoftware/smack/XMPPConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   55: astore_1
    //   56: goto -47 -> 9
    //   59: lload 5
    //   61: lconst_0
    //   62: lcmp
    //   63: ifle -14 -> 49
    //   66: aload_0
    //   67: getfield 50	org/jivesoftware/smack/XMPPConnection:roster	Lorg/jivesoftware/smack/Roster;
    //   70: lload 5
    //   72: invokevirtual 389	java/lang/Object:wait	(J)V
    //   75: invokestatic 446	java/lang/System:currentTimeMillis	()J
    //   78: lstore 9
    //   80: lload 5
    //   82: lload 9
    //   84: lload 7
    //   86: lsub
    //   87: lsub
    //   88: lstore 5
    //   90: lload 9
    //   92: lstore 7
    //   94: goto -55 -> 39
    //   97: astore 4
    //   99: aload_3
    //   100: monitorexit
    //   101: aload 4
    //   103: athrow
    //   104: astore_2
    //   105: goto -54 -> 51
    //
    // Exception table:
    //   from	to	target	type
    //   28	51	97	finally
    //   66	101	97	finally
    //   21	28	104	java/lang/InterruptedException
    //   101	104	104	java/lang/InterruptedException
  }

  public String getUser()
  {
    String str;
    if (!(isAuthenticated()))
      str = null;
    while (true)
    {
      return str;
      str = this.user;
    }
  }

  public boolean isAnonymous()
  {
    return this.anonymous;
  }

  public boolean isAuthenticated()
  {
    return this.authenticated;
  }

  public boolean isConnected()
  {
    return this.connected;
  }

  public boolean isSecureConnection()
  {
    return isUsingTLS();
  }

  public boolean isUsingCompression()
  {
    return this.usingCompression;
  }

  public boolean isUsingTLS()
  {
    return this.usingTLS;
  }

  /**
   * @deprecated
   */
  public void login(String paramString1, String paramString2, String paramString3)
    throws XMPPException
  {
    monitorenter;
    try
    {
      throw new IllegalStateException("Not connected to server.");
    }
    finally
    {
      String str2;
      monitorexit;
      throw localObject;
      if (this.authenticated)
        throw new IllegalStateException("Already logged in to server.");
      String str1 = paramString1.toLowerCase().trim();
      if ((this.config.isSASLAuthenticationEnabled()) && (this.saslAuthentication.hasNonAnonymousAuthentication()))
        if (paramString2 != null)
        {
          str2 = this.saslAuthentication.authenticate(str1, paramString2, paramString3);
          if (str2 == null)
            break label295;
          this.user = str2;
          this.config.setServiceName(StringUtils.parseServer(str2));
          if (this.config.isCompressionEnabled())
            useCompression();
          if (this.roster == null)
          {
            if (this.rosterStorage != null)
              break label365;
            this.roster = new Roster(this);
          }
        }
      while (true)
      {
        while (true)
        {
          do
          {
            while (true)
            {
              while (true)
              {
                if (this.config.isRosterLoadedAtLogin())
                  this.roster.reload();
                if (this.config.isSendPresence())
                  this.packetWriter.sendPacket(new Presence(Presence.Type.available));
                this.authenticated = true;
                this.anonymous = false;
                this.config.setLoginInfo(str1, paramString2, paramString3);
                if ((this.config.isDebuggerEnabled()) && (this.debugger != null))
                  this.debugger.userHasLogged(this.user);
                monitorexit;
                return;
                str2 = this.saslAuthentication.authenticate(str1, paramString3, this.config.getCallbackHandler());
              }
              str2 = new NonSASLAuthentication(this).authenticate(str1, paramString2, paramString3);
            }
            label295: this.user = str1 + "@" + getServiceName();
          }
          while (paramString3 == null);
          this.user = this.user + "/" + paramString3;
        }
        label365: this.roster = new Roster(this, this.rosterStorage);
      }
    }
  }

  /**
   * @deprecated
   */
  public void loginAnonymously()
    throws XMPPException
  {
    monitorenter;
    try
    {
      throw new IllegalStateException("Not connected to server.");
    }
    finally
    {
      Object localObject2;
      monitorexit;
      throw localObject1;
      if (this.authenticated)
        throw new IllegalStateException("Already logged in to server.");
      if ((this.config.isSASLAuthenticationEnabled()) && (this.saslAuthentication.hasAnonymousAuthentication()))
        localObject2 = this.saslAuthentication.authenticateAnonymously();
      while (true)
      {
        this.user = ((String)localObject2);
        this.config.setServiceName(StringUtils.parseServer((String)localObject2));
        if (this.config.isCompressionEnabled())
          useCompression();
        this.roster = null;
        this.packetWriter.sendPacket(new Presence(Presence.Type.available));
        this.authenticated = true;
        this.anonymous = true;
        if ((this.config.isDebuggerEnabled()) && (this.debugger != null))
          this.debugger.userHasLogged(this.user);
        monitorexit;
        return;
        String str = new NonSASLAuthentication(this).authenticateAnonymously();
        localObject2 = str;
      }
    }
  }

  void proceedTLSReceived()
    throws Exception
  {
    KeyStore localKeyStore;
    KeyManagerFactory localKeyManagerFactory;
    SSLContext localSSLContext = SSLContext.getInstance("TLS");
    Object localObject1 = (KeyManager[])null;
    Object localObject2 = null;
    if (this.config.getCallbackHandler() == null)
    {
      TrustManager[] arrayOfTrustManager = new TrustManager[1];
      arrayOfTrustManager[0] = new ServerTrustManager(getServiceName(), this.config);
      SecureRandom localSecureRandom = new SecureRandom();
      localSSLContext.init(localObject1, arrayOfTrustManager, localSecureRandom);
      Socket localSocket = this.socket;
      this.socket = localSSLContext.getSocketFactory().createSocket(localSocket, localSocket.getInetAddress().getHostName(), localSocket.getPort(), true);
      this.socket.setSoTimeout(0);
      this.socket.setKeepAlive(true);
      initReaderAndWriter();
      ((SSLSocket)this.socket).startHandshake();
      this.usingTLS = true;
      this.packetWriter.setWriter(this.writer);
      this.packetWriter.openStream();
      return;
    }
    if (this.config.getKeystoreType().equals("NONE"))
    {
      localKeyStore = null;
      localObject2 = null;
      localKeyManagerFactory = KeyManagerFactory.getInstance("SunX509");
      if (localObject2 != null)
        break label547;
    }
    try
    {
      while (true)
      {
        localKeyManagerFactory.init(localKeyStore, null);
        KeyManager[] arrayOfKeyManager = localKeyManagerFactory.getKeyManagers();
        localObject1 = arrayOfKeyManager;
      }
      label547: if (this.config.getKeystoreType().equals("PKCS11"));
    }
    catch (Exception localException3)
    {
      PasswordCallback localPasswordCallback2;
      try
      {
        Class localClass = Class.forName("sun.security.pkcs11.SunPKCS11");
        Class[] arrayOfClass = new Class[1];
        arrayOfClass[0] = InputStream.class;
        Constructor localConstructor = localClass.getConstructor(arrayOfClass);
        String str = "name = SmartCard\nlibrary = " + this.config.getPKCS11Library();
        ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(str.getBytes());
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = localByteArrayInputStream;
        Provider localProvider = (Provider)localConstructor.newInstance(arrayOfObject);
        Security.addProvider(localProvider);
        localKeyStore = KeyStore.getInstance("PKCS11", localProvider);
        localPasswordCallback2 = new PasswordCallback("PKCS11 Password: ", false);
      }
      catch (Exception localException3)
      {
        try
        {
          while (true)
          {
            while (true)
            {
              while (true)
              {
                CallbackHandler localCallbackHandler2 = this.config.getCallbackHandler();
                Callback[] arrayOfCallback2 = new Callback[1];
                arrayOfCallback2[0] = localPasswordCallback2;
                localCallbackHandler2.handle(arrayOfCallback2);
                char[] arrayOfChar3 = localPasswordCallback2.getPassword();
                localKeyStore.load(null, arrayOfChar3);
                localObject2 = localPasswordCallback2;
              }
              localException3 = localException3;
              localKeyStore = null;
              localObject2 = null;
            }
            if (!(this.config.getKeystoreType().equals("Apple")))
              break;
            localKeyStore = KeyStore.getInstance("KeychainStore", "Apple");
            localKeyStore.load(null, null);
          }
          localKeyStore = KeyStore.getInstance(this.config.getKeystoreType());
        }
        catch (Exception localException2)
        {
          PasswordCallback localPasswordCallback1;
          try
          {
            localPasswordCallback1 = new PasswordCallback("Keystore Password: ", false);
          }
          catch (Exception localException2)
          {
            try
            {
              while (true)
              {
                CallbackHandler localCallbackHandler1 = this.config.getCallbackHandler();
                Callback[] arrayOfCallback1 = new Callback[1];
                arrayOfCallback1[0] = localPasswordCallback1;
                localCallbackHandler1.handle(arrayOfCallback1);
                FileInputStream localFileInputStream = new FileInputStream(this.config.getKeystorePath());
                char[] arrayOfChar2 = localPasswordCallback1.getPassword();
                localKeyStore.load(localFileInputStream, arrayOfChar2);
                localObject2 = localPasswordCallback1;
              }
              localException2 = localException2;
              localKeyStore = null;
              localObject2 = null;
            }
            catch (Exception localException4)
            {
              try
              {
                char[] arrayOfChar1 = localObject2.getPassword();
                localKeyManagerFactory.init(localKeyStore, arrayOfChar1);
                localObject2.clearPassword();
              }
              catch (NullPointerException localNullPointerException)
              {
                while (true)
                {
                  while (true)
                  {
                    while (true)
                      localObject1 = (KeyManager[])null;
                    localException1 = localException1;
                  }
                  localException4 = localException4;
                }
              }
            }
          }
        }
      }
    }
  }

  public void removePacketWriterInterceptor(PacketInterceptor paramPacketInterceptor)
  {
    removePacketInterceptor(paramPacketInterceptor);
  }

  public void removePacketWriterListener(PacketListener paramPacketListener)
  {
    removePacketSendingListener(paramPacketListener);
  }

  public void sendPacket(Packet paramPacket)
  {
    if (!(isConnected()))
      throw new IllegalStateException("Not connected to server.");
    if (paramPacket == null)
      throw new NullPointerException("Packet is null.");
    this.packetWriter.sendPacket(paramPacket);
  }

  void setAvailableCompressionMethods(Collection<String> paramCollection)
  {
    this.compressionMethods = paramCollection;
  }

  public void setRosterStorage(RosterStorage paramRosterStorage)
    throws IllegalStateException
  {
    if (this.roster != null)
      throw new IllegalStateException("Roster is already initialized");
    this.rosterStorage = paramRosterStorage;
  }

  protected void shutdown(Presence paramPresence)
  {
    if (this.packetWriter != null)
      this.packetWriter.sendPacket(paramPresence);
    setWasAuthenticated(this.authenticated);
    this.authenticated = false;
    this.connected = false;
    if (this.packetReader != null)
      this.packetReader.shutdown();
    if (this.packetWriter != null)
      this.packetWriter.shutdown();
    try
    {
      Thread.sleep(150L);
      label112: if (this.reader != null);
    }
    catch (Exception localException1)
    {
      try
      {
        this.reader.close();
        this.reader = null;
        if (this.writer != null);
      }
      catch (Exception localException1)
      {
        try
        {
          this.writer.close();
          this.writer = null;
        }
        catch (Exception localException1)
        {
          try
          {
            this.socket.close();
            this.saslAuthentication.init();
            return;
            localException1 = localException1;
          }
          catch (Exception localException2)
          {
            while (true)
            {
              while (true)
              {
                break label112:
                localThrowable1 = localThrowable1;
              }
              localThrowable2 = localThrowable2;
            }
          }
        }
      }
    }
  }

  void startStreamCompression()
    throws Exception
  {
    this.usingCompression = true;
    initReaderAndWriter();
    this.packetWriter.setWriter(this.writer);
    this.packetWriter.openStream();
    monitorenter;
    try
    {
      notify();
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  void startTLSReceived(boolean paramBoolean)
  {
    if ((paramBoolean) && (this.config.getSecurityMode() == ConnectionConfiguration.SecurityMode.disabled))
      this.packetReader.notifyConnectionError(new IllegalStateException("TLS required by server but not allowed by connection configuration"));
    do
      return;
    while (this.config.getSecurityMode() == ConnectionConfiguration.SecurityMode.disabled);
    try
    {
      this.writer.write("<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>");
      this.writer.flush();
    }
    catch (IOException localIOException)
    {
      this.packetReader.notifyConnectionError(localIOException);
    }
  }

  void streamCompressionDenied()
  {
    monitorenter;
    try
    {
      notify();
      monitorexit;
      return;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }
}